<template>
	<view class="content">
		<button @click="init" class="btu">初始化</button>

		<button @click="login" class="btu">淘宝授权登录</button>

        <button @click="getuserinfo" class="btu">获取用户授权信息</button>

		<button @click="logout" class="btu">退出淘宝登录</button>

		<button @click="openurl" class="btu">打开优惠券</button>
		
		<button @click="openqdurl" class="btu">打开渠道备案</button>
		
		<button @click="openh5url" class="btu">H5授权（可以用来渠道备案）</button> 
		
		<button @click="opendetail" class="btu">打开商品详情</button>

		<button @click="openshop" class="btu">打开店铺</button>

		<button @click="openmycart" class="btu">打开我的购物车</button>

		
		<text>{{title}}</text>
	</view>
</template>

<script>
	const Alibcsdk = uni.requireNativePlugin('UZK-Alibcsdk');

	export default {
		data() {
			return {
				"title": ""
			}
		},
		onLoad() {

		},
		methods: {
			init() {
				Alibcsdk.init(
					result => {
						console.log(result)
						if(result.status){
							uni.showToast({
								title: "初始化成功"
							});
						}else{
							uni.showToast({
								title: "初始化失败"
							});
						}
						console.log(JSON.stringify(result))
					}
				)
			},
			login() { //授权登录
				Alibcsdk.login(
					result => {
						if(result.status){
							uni.showToast({
								title: "授权登陆成功"
							});
						}
						console.log(JSON.stringify(result))
					}
				)
			},
			logout() {
				Alibcsdk.logout(
					result => {
					if(result.status){
						uni.showToast({
							title: "登出成功"
						});
					}	
						console.log(JSON.stringify(result))
					}
				)
			},
			openurl() {
				var url =
					"https://uland.taobao.com/coupon/edetail?spm=a311n.9159044%2Fnew2019.19184768.1&e=FnN7yyC4dDENfLV8niU3R5TgU2jJNKOfNNtsjZw%2F%2FoJa3UC6%2BxeMcvutwNVTX3KSLspxGy3zBjap%2B7s0sowtFPv0%2FvoXyvpgzdTtiOUchMjLkU4k%2FaBIVWVfKa%2BhVnNDLVAuU8CMzMdDN4WEWA%2BAQJjB6TX2HR3QWPoiHfuLmMmYBFolcv5ukJVnRh%2ByXggR%2BnoDgTNhwmM%3D&app_pvid=59590_11.21.12.113_437_1567994479465&ptl=floorId%3A21801%3Bapp_pvid%3A59590_11.21.12.113_437_1567994479465%3Btpp_pvid%3A80bf32d7-c746-4719-b292-9d9082df9a4e&union_lens=lensId%3An%401567994479%4080bf32d7-c746-4719-b292-9d9082df9a4e_594360302497%401%3Brecoveryid%3A201_11.142.52.250_1238534_1567994478674%3Bprepvid%3A201_11.142.52.250_1238534_1567994478674&pid=mm_33231688_7050284_23466709";
				Alibcsdk.openurl({
					url: url,
					linkkey: "taobao",
					adzoneid: "59600050",
					pid: "mm_131245267_59600050_103062550066",
					nativeFailedMode: "download",
					appkey: "27142849",
					opentype: 'native'
				}, result => {

				})
			},
			/*
			渠道备案可以使用通用的渠道备案链接（可在淘宝联盟后台获取）后面拼接上rtag参数，改参数为自定义参数，可以为用户ID，用户通过该页面备案成功后
			可通过taobao.tbk.sc.publisher.info.get( 淘宝客-公用-私域用户备案信息查询 )这个接口来获取对应rtag的渠道ID。页面地址：
			https://open.taobao.com/api.htm?docId=37989&docType=2&scopeId=14474
			*/
			openqdurl() {
				var url = "https://mos.m.taobao.com/inviter/register?inviterCode=2W7YYZ&src=pub&app=common&rtag=123456";
				Alibcsdk.openurl({
					url: url,
				}, result => {
			
				})
			},
			/*
			申请渠道可以使用该方法打开H5授权登录页面，从服务端获取到access_token在调用渠道备案接口。
			H5授权登录换取access_token见淘宝联盟开发平台，页面地址：https://open.taobao.com/doc.htm?docId=118&docType=1&spm=a219a.7395903.0.0.16af3971ApSa3N
			https://oauth.m.taobao.com/authorize?response_type=code&client_id=你的appkey&redirect_uri=你的回调地址&state=自定义参数&view=web
			*/
			openh5url() {
				var url = "https://oauth.m.taobao.com/authorize?response_type=code&client_id=28002500&redirect_uri=http://m.baidu.com&state=1212&view=web";
				Alibcsdk.openurl({
					url: url,
				}, result => {
			
				})
			},
			opendetail() {
				Alibcsdk.opendetail({
					itemid: '563275619905',
					linkkey: "taobao",
					adzoneid: "59600050",
					pid: "mm_131245267_59600050_103062550066",
					nativeFailedMode: "download",
					appkey: "27142849",
					opentype: 'native'
				}, result => {

				})
			},
			openshop() {
				Alibcsdk.openshop({
					shopid: 57630185,
					sellerid: '202224264',
					linkkey: "taobao",
					adzoneid: "59600050",
					pid: "mm_131245267_59600050_103062550066",
					nativeFailedMode: "download",
					appkey: "27142849",
					opentype: 'native'
				}, result => {

				})
			},
			openmycart() {
				Alibcsdk.openmycart({
					linkkey: "taobao",
					adzoneid: "59600050",
					pid: "mm_131245267_59600050_103062550066",
					nativeFailedMode: "download",
					appkey: "27142849",
					opentype: 'native'
				}, result => {

				})
			},
			getuserinfo(){
				Alibcsdk.getuserinfo(
				result => {
					if(result.status){
						uni.showToast({
							title: "获取数据成功"
						});
					}else{
						uni.showToast({
							title: "未登陆"
						});
					}
					console.log(JSON.stringify(result))
				}
				)								
			}
		}
	}
</script>

<style>
	.btu {
		margin-top: 10px;
		margin-left: 10px;
		margin-right: 10px;
	}
</style>
